local PartnerSkillRender = app.mvc.createListViewCell(...)

local PartnerSkillIconRender = import(".PartnerSkillIconRender")
--data =
function PartnerSkillRender.create(node)
    local sprite = PartnerSkillRender.extend(node or cc.CSLoader:createNode(Res.PartnerSkillItem))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init()
    return sprite
end


function PartnerSkillRender:init(data)
    self.super.init(self, data)
    self:setContentSize( self._ui.Panel:getContentSize() )
    self._icon = PartnerSkillIconRender.create(self._ui["Panel/icon"])
   
    self._ui["Panel/Button_up"]:addClickEventListener(function()
        EM:notify(ViewEvent.Partner_SkillLevelUpClick, self)
    end)
    self._ui["Panel/Button_form"]:setVisible(false)
    
    --local timeLine = self:getTimeline()

    self._timeLine = cc.CSLoader:createTimeline(Res.PartnerSkillItem)
    self:stopAllActions()
    self:runAction(self._timeLine)
    self._endFrame = 13
    self._startFrame = 1
    self._timeLine:gotoFrameAndPause(self._endFrame)
    
    self:registerViewEvent({
        {name = ViewEvent.Partner_SkillLevelUpMax, callback = handler(self, self._onSkillLevelUpMax)},
    })
    self:refresh()
end

function PartnerSkillRender:_onSkillLevelUpMax(event, data)
    if not self._data or not data then
        return
    end
    if self._data:getSlot() == data:getSlot() and self._data:isMaxLevel() then
        -- self._ui["Panel/icon_max"]:setVisible(true)
        self._timeLine:play( "max",false )
    end
end

function PartnerSkillRender:refresh()
    if not self._data then
        return
    end
    local data = self._data
    local isUnlock = data:isUnlock()
    if isUnlock then
        self._ui["Panel/Button_form"]:setVisible(false)
        self._ui["Panel/Button_up"]:setVisible(true)
        if data:isMaxLevel() then
            if not self._timeLine:isPlaying() then
                self._timeLine:gotoFrameAndPause(self._endFrame)
            end
            self._ui["Panel/Button_up"]:setVisible(false)
        else
            self._timeLine:gotoFrameAndPause(self._startFrame)
            self._ui["Panel/Button_up"]:setVisible(not data:isDisableUpgrade())
        end
        display.applyShaderByName(self._ui["Panel"])
    else
        self._timeLine:gotoFrameAndPause(self._startFrame)
        -- self._ui["Panel/Button_form"]:setVisible(true)
        self._ui["Panel/Button_up"]:setVisible(false)
        display.applyShaderByName(self._ui["Panel"], "ShaderGray")
    end

    self._icon:setData(data)
    self._ui["Panel/name"]:setString(data:getName())
    self._ui["Panel/lv"]:setString(L("lua_code_text_379")..tostring(data:getLevel()))
    -- self._ui["Panel/icon"]:loadTexture(data:getIcon())
end

function PartnerSkillRender:setIndex(index)
    self._index = index
end

function PartnerSkillRender:getIndex()
    return self._index
end

return PartnerSkillRender